package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/8/22 10:24
 * @Version 1.0
 */
@Controller
public class ItemController {

    @Autowired
    private ItemFeignClient itemFeignClient;

    //  http://item.gmall.com/27.html
    @GetMapping("{skuId}.html")
    public String item(@PathVariable Long skuId, Model model){
        //  获取商品详情数据
        Result<Map> result = itemFeignClient.getSkuItem(skuId);
        //  数据存储
        model.addAllAttributes(result.getData());
        //  返回商品详情页面
        return "item/item";
    }
}
